import requests


def send_post_request(url, json_data):
    try:
        headers = {'Content-Type': 'application/json'}
        response = requests.post(url, json=json_data, headers=headers)
        if response.status_code == 200:
            # 请求成功，返回响应内容
            return response.text
        else:
            # 请求失败，打印错误信息
            print("POST请求失败：", response.status_code)
            return None
    except Exception as e:
        # 发生异常，打印异常信息
        print("发生异常：", e)
        return None


# 测试发送POST请求的函数
if __name__ == "__main__":
    # 设置POST请求的URL和要发送的数据
    url = "http://127.0.0.1:5001/startLocalSimulator"
    data = {
        "userId": "123",
        "taskId": "124",
        "proj": "+proj=tmerc +lon_0=113.30785068935498 +lat_0=22.97959059227457 +ellps=WGS84",
        "netPath": "E:\\01文档\\00仿真项目\\数据集\\webgl_simulation\\webgl\\qifusuidao.tess"
    }

    # 调用发送POST请求的函数
    result = send_post_request(url, data)
    if result:
        print("POST请求成功，响应内容：", result)
    else:
        print("POST请求失败")
